package commons.data.category;

import java.util.regex.Pattern;


public class Filter {

	public String fieldName;
	public String strPattern;

	private Pattern pattern;

	public Filter(String fieldName, String strPattern) {
		this.fieldName = fieldName;
		this.strPattern = strPattern;

		if (strPattern != null)
			pattern = Pattern.compile(strPattern);
		else
			pattern = null;
	}

	public boolean matchField (String fieldValue) {
		if (this == allPassFilter)
			return true;

		if (this == nothingPassFilter)
			return false;

		return pattern.matcher(fieldValue).matches();
	}


	public static Filter allPassFilter;
	public static Filter nothingPassFilter;
	static {
		allPassFilter = new Filter(null, null);
		nothingPassFilter = new Filter(null, null);
	}

}
